package com.test;

import java.io.FileInputStream;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.Properties;

public class DAO {

	private Connection getConnection() throws Exception {
		DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
		Properties props = new Properties();
		FileInputStream fichero = new FileInputStream("resources/dbprops.properties");
		props.load(fichero);
		StringBuilder cadenaConnexion = new StringBuilder();
		cadenaConnexion.append("jdbc:oracle:thin:@").append(props.get("host")).append(":").append(props.get("port")).append(":").append(props.get("sid"));
		String cadenaCnx = cadenaConnexion.toString();
		String usuario = props.getProperty("user");
		String password = props.getProperty("password");
		System.out.println("[" + cadenaCnx + "][usuario=" + usuario + ", password=" + password + "]");
		return DriverManager.getConnection(cadenaCnx, usuario, password);
	}

	public void test() throws Exception {
		Connection conn = getConnection();
		Statement stmt = conn.createStatement();
		ResultSet rset = stmt.executeQuery("select BANNER from SYS.V_$VERSION");
		while (rset.next()) {
			System.out.println(rset.getString(1)); // Print col 1
		}
		stmt.close();
	}

}
